import React from 'react'

import {Form, Input, Tooltip, Icon, Cascader, Select, Row, Col, Checkbox, Button, AutoComplete} from 'antd';
const FormItem = Form.Item;

class AddRoleForm extends React.Component {
    state = {
        A: '123',
    };
    handleSubmit = () => {
        let vm =this;
        this.props.form.validateFieldsAndScroll((err, values) => {
            if (!err) {
                //调用父组件的回调函数
                vm.props.addRoleCallback(values);
            }
        });
    };
    //清空表单
    resetFields(){
        this.props.form.resetFields()
    }
    render() {
        const {getFieldDecorator} = this.props.form;
        const formItemLayout = {
            labelCol: {
                xs: {span: 4},
                sm: {span: 4},
                md: {span: 6},

            },
            wrapperCol: {
                xs: {span: 20},
                sm: {span: 20},
                md: {span: 18},
            },
        };
        return (
            <Form onSubmit={this.handleSubmit}>
                <Row>
                    <Col xs={24} sm={24} md={24} lg={24} xl={24}>
                        <FormItem
                            {...formItemLayout}
                            label={(
                                <span>编号&nbsp;</span>
                            )}>
                            {getFieldDecorator('code', {
                                rules: [{required: true, message: '请输入编号', whitespace: true}],
                                initialValue: this.props.roleObject.code
                            })(
                                <Input/>
                            )}
                        </FormItem>
                    </Col>
                    <Col xs={24} sm={24} md={24} lg={24} xl={24}>
                        <FormItem
                            {...formItemLayout}
                            label={(
                                <span>名称&nbsp;</span>
                            )}>
                            {getFieldDecorator('name', {
                                rules: [{required: true, message: '请输入名称', whitespace: true}],
                                initialValue: this.props.roleObject.name
                            })(
                                <Input/>
                            )}
                        </FormItem>
                    </Col>
                </Row>
            </Form>
        )
    }
}
let addRoleForm = Form.create()(AddRoleForm);
export default addRoleForm